/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.Entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author KIS
 */
@Entity
@Table(name = "companyUser", catalog = "Final_Project_Sem_IV", schema = "dbo", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"email"}),
    @UniqueConstraint(columnNames = {"phoneNumber"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CompanyUser.findAll", query = "SELECT c FROM CompanyUser c"),
    @NamedQuery(name = "CompanyUser.findById", query = "SELECT c FROM CompanyUser c WHERE c.id = :id"),
    @NamedQuery(name = "CompanyUser.findByLoginCode", query = "SELECT c FROM CompanyUser c WHERE c.loginCode = :loginCode"),
    @NamedQuery(name = "CompanyUser.findByLoginPass", query = "SELECT c FROM CompanyUser c WHERE c.loginPass = :loginPass"),
    @NamedQuery(name = "CompanyUser.findByFirstName", query = "SELECT c FROM CompanyUser c WHERE c.firstName = :firstName"),
    @NamedQuery(name = "CompanyUser.findByLastName", query = "SELECT c FROM CompanyUser c WHERE c.lastName = :lastName"),
    @NamedQuery(name = "CompanyUser.findByGender", query = "SELECT c FROM CompanyUser c WHERE c.gender = :gender"),
    @NamedQuery(name = "CompanyUser.findByDateOfBirth", query = "SELECT c FROM CompanyUser c WHERE c.dateOfBirth = :dateOfBirth"),
    @NamedQuery(name = "CompanyUser.findByEmail", query = "SELECT c FROM CompanyUser c WHERE c.email = :email"),
    @NamedQuery(name = "CompanyUser.findByPhoneNumber", query = "SELECT c FROM CompanyUser c WHERE c.phoneNumber = :phoneNumber"),
    @NamedQuery(name = "CompanyUser.findByAddress", query = "SELECT c FROM CompanyUser c WHERE c.address = :address")})
public class CompanyUser implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "id", nullable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "loginCode", nullable = false, length = 5)
    private String loginCode;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "loginPass", nullable = false, length = 50)
    private String loginPass;
    @Size(max = 20)
    @Column(name = "firstName", length = 20)
    private String firstName;
    @Size(max = 50)
    @Column(name = "lastName", length = 50)
    private String lastName;
    @Column(name = "gender")
    private Boolean gender;
    @Column(name = "dateOfBirth")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateOfBirth;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 100)
    @Column(name = "email", length = 100)
    private String email;
    @Size(max = 15)
    @Column(name = "phoneNumber", length = 15)
    private String phoneNumber;
    @Size(max = 1073741823)
    @Column(name = "address", length = 1073741823)
    private String address;
    @Lob
    @Column(name = "avatar")
    private byte[] avatar;
    @OneToMany(mappedBy = "companyUserID")
    private List<Feedback> feedbackList;
    @OneToMany(mappedBy = "authorID")
    private List<Article> articleList;
    @OneToMany(mappedBy = "solvingTechnicianID")
    private List<Complaint> complaintList;
    @OneToMany(mappedBy = "lodgingEmployeeID")
    private List<Complaint> complaintList1;
    @JoinColumn(name = "typeOfUserID", referencedColumnName = "id")
    @ManyToOne
    private TypeOfUser typeOfUserID;
    @JoinColumn(name = "departmentID", referencedColumnName = "id")
    @ManyToOne
    private Department departmentID;

    public CompanyUser() {
    }

    public CompanyUser(Integer id) {
        this.id = id;
    }

    public CompanyUser(Integer id, String loginCode, String loginPass) {
        this.id = id;
        this.loginCode = loginCode;
        this.loginPass = loginPass;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getLoginCode() {
        return loginCode;
    }

    public void setLoginCode(String loginCode) {
        this.loginCode = loginCode;
    }

    public String getLoginPass() {
        return loginPass;
    }

    public void setLoginPass(String loginPass) {
        this.loginPass = loginPass;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Boolean getGender() {
        return gender;
    }

    public void setGender(Boolean gender) {
        this.gender = gender;
    }

    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public byte[] getAvatar() {
        return avatar;
    }

    public void setAvatar(byte[] avatar) {
        this.avatar = avatar;
    }

    @XmlTransient
    public List<Feedback> getFeedbackList() {
        return feedbackList;
    }

    public void setFeedbackList(List<Feedback> feedbackList) {
        this.feedbackList = feedbackList;
    }

    @XmlTransient
    public List<Article> getArticleList() {
        return articleList;
    }

    public void setArticleList(List<Article> articleList) {
        this.articleList = articleList;
    }

    @XmlTransient
    public List<Complaint> getComplaintList() {
        return complaintList;
    }

    public void setComplaintList(List<Complaint> complaintList) {
        this.complaintList = complaintList;
    }

    @XmlTransient
    public List<Complaint> getComplaintList1() {
        return complaintList1;
    }

    public void setComplaintList1(List<Complaint> complaintList1) {
        this.complaintList1 = complaintList1;
    }

    public TypeOfUser getTypeOfUserID() {
        return typeOfUserID;
    }

    public void setTypeOfUserID(TypeOfUser typeOfUserID) {
        this.typeOfUserID = typeOfUserID;
    }

    public Department getDepartmentID() {
        return departmentID;
    }

    public void setDepartmentID(Department departmentID) {
        this.departmentID = departmentID;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CompanyUser)) {
            return false;
        }
        CompanyUser other = (CompanyUser) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.Entity.CompanyUser[ id=" + id + " ]";
    }
    
}
